package com.dfbz.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo02_线程池执行Runnable {
    public static void main(String[] args) throws Exception {

        // 创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        Future<?> runnableTask = executorService.submit(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("任务执行完毕....");

            }
        });


        // 这句话会造成线程阻塞的,因为获取任务的结果集必须要任务全部执行完毕
        Object result = runnableTask.get();

        System.out.println("执行玩这个任务获取的结果集为: " + result);
    }
}
